<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
	/**
	 * 博客首页
	 * @return [type] [description]
	 */
	public function index(){
		//显示分类
		$cate = M('Cate');
		$rescate = $cate->field('id,cate')->select();
		$this->assign('cate', $rescate);
		//文章
		$article = M('Article');
		//显示顶置文章
		$topArt = $article->where('is_top=1')->field('id,title,smallimg')->order('creattime desc')->limit(3)->select();
		$this->assign('topArt', $topArt);
		//显示最新的文章
		$newArt = $article->where('is_home=1')->field('id,title,smallimg')->order('creattime desc')->limit(3)->select();
		$this->assign('newArt', $newArt);
		//热门文章
		$hotArt = $article->field('id,title,smallimg')->order('hits desc')->limit(10)->select();
		$this->assign('hotArt', $hotArt);

		$this->display();
	}
	/**
	 * 文章列表
	 * @param  int $id [description]
	 * @return [type]     [description]
	 */
	public function listArt($cateid = "")
	{
		//显示分类
		$cate = M('Cate');
		$rescate = $cate->field('id,cate')->select();
		$this->assign('cate', $rescate);
		$where = '';
		if ($cateid != '') {
			$where = ' AND cateid=' . $cateid;
		}
		$article = M('Article');
		$blog = $article
			->table(array('bg_article'=>'a','bg_cate'=>'b'))
			->field('a.id,a.title,a.profiles,a.updatetime,a.hits,a.smallimg')
			->where("a.cateid = b.id" . $where)
			->order('is_top desc,updatetime desc')
			->select();
		$this->assign('blog', $blog);
		$this->display();
	}
	/**
	 * 文章展示
	 * @param  int $id [description]
	 * @return [type]     [description]
	 */
	public function artdetial($id)
	{
		//显示分类
		$cate = M('Cate');
		$rescate = $cate->field('id,cate')->select();
		$this->assign('cate', $rescate);
		//文章
		$article = M('Article');
		$article->where('id=' . $id)->setInc('hits');//点击量更新
		$blogId = $article->where('id=' . $id)->field('id,title,bigimg,author,content,creattime,updatetime,hits')->find();
		$this->assign('blogId', $blogId);
		//评论
		$comment = M('comment');
		$comt = $comment->where('toart=' . $id . " AND comtId=0")->field('id,name,comtId,toname,comment,time')->order('time')->select();
		$this->assign('comt', $comt);
		//回复
		$reply = $comment->where('toart=' . $id . " AND comtId!=0")->field('id,name,comtId,toname,comment,time')->order('time')->select();
		$this->assign('reply', $reply);

		$this->display();
	}
	/**
	 * 留言页
	 * @return [type] [description]
	 */
	public function msg()
	{
		//显示分类
		$cate = M('Cate');
		$rescate = $cate->field('id,cate')->select();
		$this->assign('cate', $rescate);
		$this->display();
	}
	/**
	 * 关于本站页
	 * @return [type] [description]
	 */
	public function about()
	{
		//显示分类
		$cate = M('Cate');
		$rescate = $cate->field('id,cate')->select();
		$this->assign('cate', $rescate);
		$this->display();
	}
}